<?php header("Content-Type:text/html;   charset=utf-8"); ?>
<script type="text/javascript">	
	var curtype = "1";
	$(function(){		
		loadSite();
		$("#btnSubmitSite").bind("click",submitSite);
		$("#imgSiteLogoUrl").bind("click",function(){
			curtype="1";
			$("#fileHead").trigger("click");
		});
		$("#imgSiteLogoBottomUrl").bind("click",function(){
			curtype="2";
			$("#fileHead").trigger("click");
		});
		bindSubmitSite();
		$("#fileHead").bind("change",loadSiteImg);
		$("#btnDelHeadLogo").bind("click",function(){
			saveSiteHeadLogoUrl("");
			loadSite();
		});
		$("#btnDelBottomLogo").bind("click",function(){
			saveSiteBottomLogoUrl("");
			loadSite();
		});
		
	});	
	function bindSubmitSite(){	
		var options = {  
		        beforeSubmit:  showRequestSite,  //提交前处理 
		        success:       showResponseSite,  //处理完成 
		        resetForm: false,  
		        dataType:  'json'  
		    };  
		  
		    $('#formSite').submit(function() {			    
		        $(this).ajaxSubmit(options);
		        return false;
		    });  
	}
	function showRequestSite(formData, jqForm, options) {		
	    return true;  
	}  
	  
	function showResponseSite(data, statusText)  {
	    if(data.ReturnCode==1){
		    if(curtype=="1"){
		    	 $("#imgSiteLogoUrl").attr("src",data.src);
			     saveSiteHeadLogoUrl(data.src);
			}else{
				$("#imgSiteLogoBottomUrl").attr("src",data.src);
			     saveSiteBottomLogoUrl(data.src);
			}
	    }else{
	        
	    }
	    return false;   
	} 
	function saveSiteHeadLogoUrl(src){
		var params = {headlogourl:src};
		$.ajax({
			type:"post",
			url:"admin.php/manage/setHeadLogoUrl",
			dataType:"json",
			data:params,
			async:false,
			success:function(data){
				
			}
		});
	}
	function saveSiteBottomLogoUrl(src){
		var params = {bottomLogoUrl:src};
		$.ajax({
			type:"post",
			url:"admin.php/manage/setBottomLogoUrl",
			dataType:"json",
			data:params,
			async:false,
			success:function(data){
				
			}
		});
	}
	function submitSite(){	
		if(checkSite("txtSiteName",100)==false)
			return false;
		if(checkSite("txtSiteTitle",100)==false)
			return false;
		if(checkSite("txtSiteKeyWords",1000)==false)
			return false;
		if(checkSite("txtSiteDesc",100)==false)
			return false;
		if(checkSite("txtSiteLogo",50)==false)
			return false;
		if(checkSite("txtSiteBottomLogo",50)==false)
			return false;
		if(checkSite("txtSiteBeian",250)==false)
			return false;
		if(checkSite("txtSiteStaCode",500)==false)
			return false;	
		var name = $("#txtSiteName").val();
		var title = $("#txtSiteTitle").val();
		var keywords = $("#txtSiteKeyWords").val();
		
		var sitedesc = $("#txtSiteDesc").val();
		var headlogo = $("#txtSiteLogo").val();
		var headlogourl = $("#imgSiteLogoUrl").attr("src");
		var bottomlogo = $("#txtSiteBottomLogo").val();
		var bottomlogourl = $("#imgSiteLogoBottomUrl").attr("src");
		var beian = $("#txtSiteBeian").val();
		var stacode = $("#txtSiteStaCode").val();
		var status= $("#selSiteStatus").val();
		var bottominfo = $("#txtSiteBottomInfo").val();
		var reginfo = $("#txtSiteRegInfo").val();
		var anticheatguide = $("#txtSiteAntiCheatGuide").val();

		var params = {
					name:name,
					title:title,
					keywords:keywords,
					sitedesc:sitedesc,
					headlogo:headlogo,					
					bottomlogo:bottomlogo,					
					beian:beian,
					stacode:stacode,
					status:status,
					bottominfo:bottominfo,
					reginfo:reginfo,
					anticheatguide:anticheatguide
				};
		//alert(params.name+"-"+params.title+"-"+params.keywords+"-"+params.sitedesc+"-"+params.headlogo+"-"+params.bottomlogo
		//		+"-"+params.beian+"-"+params.stacode+"-"+params.status+"-"+params.bottominfo+"-"+params.reginfo+"-"+params.anticheatguide);
		
		$.ajax({
			type:"post",
			url:"admin.php/manage/setSite",
			dataType:"json",
			data:params,
			success:function(data){
				loadSite();
				alert("提交成功");
			}
		});
	}
	
	function loadSite(){		
		$.ajax({
			type:"post",
			url:"admin.php/manage/getSite",
			dataType:"json",			
			success:function(data){
				$("#txtSiteName").val(data.name);
				$("#txtSiteTitle").val(data.title);
				$("#txtSiteKeyWords").val(data.keywords);
				$("#txtSiteDesc").val(data.sitedesc);
				$("#txtSiteLogo").val(data.headlogo);
				$("#imgSiteLogoUrl").attr("src",data.headlogourl);
				$("#txtSiteBottomLogo").val(data.bottomlogo);
				$("#imgSiteLogoBottomUrl").attr("src",data.bottomlogourl);
				$("#txtSiteBeian").val(data.beian);
				$("#txtSiteStaCode").val(data.stacode);
				$("#selSiteStatus").val(data.status);
				$("#txtSiteBottomInfo").val(data.bottominfo);
				$("#txtSiteRegInfo").val(data.reginfo);
				$("#txtSiteAntiCheatGuide").val(data.anticheatguide);
			}
		});
	}

	function loadSiteImg(){
		var fileName = $("#fileHead").val();
		var ext=fileName.substr(fileName.indexOf(".")).toLowerCase();
		if(ext!=".gif" && ext!=".jpg" && ext!=".jpeg" && ext!=".png" && ext!=""){
			alert("图片格式无效");		
			return;
		}
		if(!IsEmpty(fileName)){	
			$("#formSite").submit();
			return false;
		}	
	}
	function checkSite(id,len){
		var name = $("#"+id).val();
		var length = name.length;
		if(length>len){
			SetError(id,"最多"+len+"个字符");
			return false;
		}
		ClearError(id);
		return true;
	}
	
</script>
<div class="pageContent">
	<form id="formSite" class="pageForm required-validate" action="admin.php/manage/uploadImg/mypic1" method="post"
		enctype="multipart/form-data">
		<div class="pageFormContent" style="width: 98%;" layoutH="56">
			<input type='file' id='fileHead' name='mypic1' style='display: none'>
			
			<table class="tableNewUser">
				<tr>
					<td>网站名称：</td>
					<td colspan="2"><input id="txtSiteName" type="text" value="" /></td>
				</tr>
				<tr>
					<td>网站标题：</td>
					<td colspan="2"><input id="txtSiteTitle" type="text" value="" /></td>
				</tr>
				<tr>
					<td>网站关键词：</td>
					<td colspan="2"><input type="text" id="txtSiteKeyWords"></td>
				</tr>
				<tr>
					<td>网站描述：</td>
					<td colspan="2"><input type="text" id="txtSiteDesc"></td>
				</tr>
				
				<tr>
					<td>网站Logo：</td>
					<td style="vertical-align: middle; line-height: 130px; clear: both;width:260px;"><input
						type="text" id="txtSiteLogo" style="clear: both"></td>
					<td style="text-align: left"><img id="imgSiteLogoUrl"
						style="width: 60px; height: 60px; vertical-align: middle; cursor: pointer">

						<input type="button" id="btnDelHeadLogo" value="删除"
						style="width: 80px"></td>
				</tr>
				<tr>
					<td>网站底部Logo：</td>
					<td><input type="text" id="txtSiteBottomLogo" style="clear: both"></td>
					<td><img id="imgSiteLogoBottomUrl"
						style="width: 60px; height: 60px; vertical-align: middle; cursor: pointer">
						<input type="button" id="btnDelBottomLogo" value="删除"
						style="width: 80px" /></td>
				</tr>
				<tr>
					<td>网站备案信息：</td>
					<td colspan="2"><input type="text" id="txtSiteBeian"></td>
				</tr>
				<tr>
					<td>网站统计代码：</td>
					<td colspan="2"><input type="text" id="txtSiteStaCode"></td>
				</tr>
				<tr>
					<td>网站开启：</td>
					<td colspan="2"><select id="selSiteStatus" style="width: 245px">
							<option value="1">网站开启</option>
							<option value="0">网站关闭</option>
					</select></td>
				</tr>
				<tr>
					<td>站点底部信息：</td>
					<td colspan="2">
						<div class="unit">
							<textarea id="txtSiteBottomInfo" class="editor"
								name="description" rows="6" cols="100" tools="simple"></textarea>
						</div>
					</td>
				</tr>
				<tr>
					<td>注册协议：</td>
					<td colspan="2">
						<div class="unit">
							<textarea id="txtSiteRegInfo" class="editor" name="description"
								rows="12" cols="100" tools="simple"></textarea>
						</div>
					</td>
				</tr>
				<tr>
					<td>防骗指南：</td>
					<td colspan="2">
						<div class="unit">
							<textarea id="txtSiteAntiCheatGuide" class="editor"
								name="description" rows="12" cols="100" tools="simple"></textarea>
						</div>
					</td>
				</tr>
				<tr>
					<td colspan="3" style='line-height: 40px'>&nbsp;&nbsp;</td>
				</tr>
			</table>
			<input type="hidden" id="hdidsite"
				value="<?php if(isset($_GET["id"])) print $_GET["id"]; else print 0;?>">

			<div class="buttonActive" style="width: 120px; margin-left: 50px;">
				<div class="buttonContent">
					<button id="btnSubmitSite" type="button" style="width: 80px">提 交</button>
				</div>
			</div>

			<div class="button" style="text-align: right">
				<div class="buttonContent" style="text-align: right">
					<button id="btnCloseSite" type="button" class="close"
						style="width: 80px">取 消</button>
				</div>
			</div>
		</div>
	</form>
</div>
